package com.java3_9;

public class Dish {
    private int dish;

    public Dish() {
    }

    public Dish(int dish) {
        this.dish = dish;
    }

    public int getDish() {
        return dish;
    }

    public void setDish(int dish) {
        this.dish = dish;
    }

    public void delDish(){
        synchronized (this){
            while(dish<=0){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            dish--;
            System.out.println(Thread.currentThread().getName() + "  刚端走了一份菜" + "现在一共有" + dish + "份菜");
            this.notifyAll();
        }
    }
    public void addDish(){
        synchronized (this){
            while(dish>=5){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            dish++;
            System.out.println(Thread.currentThread().getName() + "  又炒出了一份菜" + "现在一共有" + dish + "份菜");
            this.notifyAll();
        }
    }
}
